package com.aviation.sell_ticket.tool;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResultUtil {

    /**
     * 返回信息
     * @param resultEnum 状态
     * @param object 数据
     * @return Map<String,Object>
     */
    public static Map<String,Object> success(ResultEnum resultEnum, Object object){
        Map<String,Object> result=new HashMap<>();
        result.put("code",resultEnum.getCode());
        result.put("msg",resultEnum.getMsg());
        if(object!=null){
            result.put("data",object);
        }
        return result;
    }

    /**
     * 需要传入对象返回信息
     * @param information 信息
     * @param object 数据
     * @return Map<String,Object>
     */
    public static Map<String,Object> success(List<Object> information, Object object){
        Map<String,Object> result=new HashMap<>();
        result.put("code",information.get(0));
        result.put("msg",information.get(1));
        if(object!=null){
            result.put("data",object);
        }
        return result;
    }

    /**
     * 服务器报错返回
     * @param resultEnum 错误状态
     * @return Map<String,Object>
     */
    public static Map<String,Object> beDefeated(ResultEnum resultEnum){
        Map<String,Object> result=new HashMap<>();
        result.put("code",resultEnum.getCode());
        result.put("msg",resultEnum.getMsg());
        result.put("timestamp",String.valueOf(LocalDateTime.now()));
        return result;
    }

}
